//
//  DMFamousDoctorView.m
//  CQKuaiYi
//
//  Created by Mr.Cannon on 2017/1/8.
//  Copyright © 2017年 Mr.Cannon. All rights reserved.
//

#import "DMFamousDoctorView.h"
#import "DMFamousDoctorModel.h"
@interface DMFamousDoctorView ()<SDCycleScrollViewDelegate>
//数据模型
@property(nonatomic,strong)NSArray<DMFamousDoctorModel*>* famousDoctorModels;

@end
@implementation DMFamousDoctorView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
#pragma mark - 初始化界面
-(void)setupUI
{
    //请求获取网络数据
    [[DMNetworkTool shareDMNetwork] postURL:@"http://iosapi.itcast.cn/doctor/banners.json.php" parameter:@{@"page_size" : @10, @"page" : @1} completion:^(NSDictionary* response)
    {
        if(response==nil)
        {
            UILabel* error = [UILabel cz_labelWithText:@"网络请求失败"
                                              fontSize:22
                                                 color:[UIColor cz_randomColor]];
            error.textAlignment = NSTextAlignmentCenter;
            [self addSubview:error];
            [error mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self);
            }];
            return;
        }
        //取出模型
        NSDictionary* resultDict = response[@"data"];
        NSArray* resArr = resultDict[@"banners"];
        //转模型数组
        _famousDoctorModels = [NSArray yy_modelArrayWithClass:[DMFamousDoctorModel class] json:resArr];
        NSMutableArray* imagesURLStr = [[NSMutableArray alloc]init];
        for (DMFamousDoctorModel* model in _famousDoctorModels) {
            [imagesURLStr addObject:model.banner_img_url];
        }
        //创建SDCyclescrollView
        SDCycleScrollView* cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
        cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
        cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
        cycleScrollView.imageURLStringsGroup = imagesURLStr;
        [self addSubview:cycleScrollView];
        //布局
        [cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }];
}
@end
